package com.weidey.blogWeb.controller;


import com.weidey.blogWeb.service.ILikeService;
import com.weidey.common.core.domain.AjaxResult;
import com.weidey.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@EnableAsync
@RequestMapping("/blog/web/like")
public class WebLikeController {

    @Autowired
    private ILikeService likeService;

    /**
     *  点赞接口
     */
    @PostMapping
    public AjaxResult like( @RequestParam("targetType") Integer targetType,
                            @RequestParam("targetId") Long targetId){
        Long userId = SecurityUtils.getUserId();
       return   likeService.like(userId ,targetType, targetId);
    }

    /**
     *  获取点赞状态
     * @return true or false
     */
    @GetMapping("/get/dislike")
    public Boolean isLike(@RequestParam("targetType") Integer targetType, @RequestParam("targetId") Long targetId) {
          Long userId = SecurityUtils.getUserId();
        return   likeService.isLike(userId ,targetType, targetId);
    }

    /**
     *  获取点赞数量
     * @return 点赞数量
     */
    @GetMapping("/select/count")
    public AjaxResult getCount(@RequestParam("targetType") Integer targetType, @RequestParam("targetId") Long targetId) {
        return AjaxResult.success(likeService.getCount(targetType, targetId));
    }
}
